package demo4;

class MyThreadPool{
    //下面的这个就是进行的这个任务队列的创建
    private BlockingQuene<Runnable> quene=new ArrayBlockingQuene<>();
    public void submit(Runnable runnable){
        quene.put(runnable);
    }

    public MyThreadPool(int n){
        for(int i=0;i<n;i++){
            Thread t=new Thread(()->{
                Runnable runnnable=quene.take();
                runnable.run();
            });
        }
    }
}

public class Test {
    public static void main(String[] args) {
        MyThreadPool myThreadPool=new MyThreadPool(4);
        for(int i=0;i<1000;i++){
            int id=i;
            myThreadPool.submit(new Runnable()->{
                @Override
                        public void run(){
                    System.out.println("执行任务："+id);
                }
            });
        }
    }
}
